<template>
    <div id="dr37">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>增值业务管理</BreadcrumbItem>
            <BreadcrumbItem>求职管理</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">
            <Input v-model="selectMobile" placeholder="查询手机号码" style="width: 150px"/>
            &nbsp;
            <DatePicker v-model="startTime" type="date" placeholder="选择开始时间" style="width: 150px"></DatePicker>
            至
            <DatePicker v-model="endTime" type="date" placeholder="选择结束时间" style="width: 150px"></DatePicker>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>
            <Button type="info" @click="handleDownload()" style="float: right">下载报表</Button>
        </div>
        <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0" style="margin-top: 10px" @on-row-dblclick="rowData"></Table>

        <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
              style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
              v-if="data&&data.length>0"/>
        <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
            总计 {{pageTotal}} 条数据
        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>

        <Modal v-model="modeBool" fullscreen>
            <div style="text-align:left;font-size: 16px">
                <div style="margin: 3px">发布时间:&nbsp;<span>{{modeData.jobTime1}}</span></div>
                <div style="margin: 3px">发布手机:&nbsp;<span>{{modeData.userMobile}}</span></div>
                <div style="margin: 3px">求职车型:&nbsp;<span>{{modeData.driveTypeName}}</span></div>
                <div style="margin: 3px">驾龄:&nbsp;<span>{{modeData.driveAge}}</span></div>
                <div style="margin: 3px">驾照类型:&nbsp;<span>{{modeData.driveCardType}}</span></div>
                <div style="margin: 3px">求职地区:&nbsp;<span>{{modeData.diqu}}</span></div>
                <div style="margin: 3px">薪资:&nbsp;<span>{{modeData.salary}}</span></div>
                <div style="margin: 3px">描述:&nbsp;<span>{{modeData.remark}}</span></div>
                <div style="margin: 3px">联系人:&nbsp;<span>{{modeData.contacts}}</span></div>
                <div style="margin: 3px">联系电话:&nbsp;<span>{{modeData.mobile}}</span></div>
                <div style="margin: 3px">求职照片:</div>
                <div style="margin: 2px">
                    <img v-for="item in modeData.photo1" :src="item" alt="" style="margin: 5px"
                         width="420px">
                    <br>
                    <img v-for="item1 in modeData.photo2" :src="item1" alt="" style="margin: 5px"
                         width="420px">
                </div>

            </div>
            <div slot="footer">
                <Button type="info" @click="modeBool=false">关闭</Button>
            </div>
        </Modal>

    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                endTime: "",
                startTime: "",
                selectMobile: "",
                loading: false,
                modeData: {},
                modeBool: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '发布时间',
                        key: 'jobTime1',
                        width: 150
                    },
                    {
                        title: '手机号码',
                        key: 'userMobile',
                        width: 120
                    },
                    {
                        title: '求职车型',
                        key: 'driveTypeName',
                    },
                    {
                        title: '驾龄',
                        key: 'driveAge',
                        width: 60
                    },
                    {
                        title: '驾照类型',
                        key: 'driveCardType'
                    },
                    {
                        title: '驾驶经验',
                        key: 'drivedTruckType'
                    },
                    {
                        title: '薪资待遇',
                        key: 'salary'
                    }, {
                        title: '招聘状态',
                        key: 'jobStatus1'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            var ds = this;
                                            this.$Modal.confirm({
                                                title: "提示",
                                                content: "确定删除?",
                                                onOk(){
                                                    ds.delData(params);
                                                },
                                                onCancel(){

                                                }
                                            });
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            typeChange(){
                this.getData();
            },
            pageChange(page){
                this.getData(page);
            },
            rowData(data, index){
                this.modeData = data;
                this.modeBool = true;
            },
            search(){
                this.getData();
            },
            delData(data){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('id', data.row._id);
                this.loading = true;
                Axios.post(ipServer + "jobWanted/removeJobWantedById", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                this.data.splice(data.index, 1);
                                this.$Message.info("删除成功!");
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('blacklistStatus', "2");
                param.append('userType', this.type);
                if (page) {
                    param.append('pageId', page + "");
                }
                if (this.startTime) {
                    param.append('startTime', sessionUtils.DateToTime(this.startTime) + "");
                }
                if (this.endTime) {
                    param.append('endTime', sessionUtils.DateToTime(this.endTime) + "");
                }
                if (this.selectMobile) {
                    param.append('publishMobile', this.selectMobile + "");
                }
                this.loading = true;
                Axios.post(ipServer + "jobWanted/selectJobWantedList", param)
                        .then(res => {
                            if (res.data.code == 0) {

                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].jobTime1 = sessionUtils.timestampToTime(res.data.data.result[i].jobTime);
                                    if (res.data.data.result[i].jobStatus == 0) {
                                        res.data.data.result[i].jobStatus1 = "未求职";
                                    } else {
                                        res.data.data.result[i].jobStatus1 = "求职中";
                                    }

                                    if (res.data.data.result[i].cardPhoto) {
                                        res.data.data.result[i].photo1 = res.data.data.result[i].cardPhoto.split(',');

                                        for (var j = 0; j < res.data.data.result[i].photo1.length; j++) {
                                            res.data.data.result[i].photo1[j] = "http://p5thuz78a.bkt.clouddn.com/" + res.data.data.result[i].photo1[j];
                                        }
                                    }
                                    if (res.data.data.result[i].driveCardPhoto) {
                                        res.data.data.result[i].photo2 = res.data.data.result[i].driveCardPhoto.split(',');
                                        for (var j = 0; j < res.data.data.result[i].photo2.length; j++) {
                                            res.data.data.result[i].photo2[j] = "http://p5thuz78a.bkt.clouddn.com/" + res.data.data.result[i].photo2[j];
                                        }
                                    }
                                    res.data.data.result[i].diqu = res.data.data.result[i].provinceName + res.data.data.result[i].cityName;
                                }


                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }, handleDownload() {
                this.loading = true;
                const list = this.data;
                require.ensure([], () => {
                    const {export_json_to_excel} = require('../../assets/js/Export2Excel') //这个地址和页面的位置相关，这个地址是Export2Excel.js相对于页面的相对位置
                    const tHeader = ["发布时间", "手机号码", "求职车型", "驾龄", "驾照类型", "驾驶经验", "薪资待遇", "招聘状态"]; //这个是表头名称 可以是iveiw表格中表头属性的title的数组
                    const filterVal = ["jobTime1", "userMobile", "driveTypeName", "driveAge", "driveCardType", "drivedTruckType", "salary", "jobStatus1"]; //与表格数据配合 可以是iview表格中的key的数组
                    const data = this.formatJson(filterVal, list)
                    export_json_to_excel(tHeader, data, '求职列表') //列表excel  这个是导出表单的名称
                    this.loading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>